<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.util.logging.Level,java.util.logging.Logger" %>
<%@ page import="java.sql.Statement"%>
<%@page import="java.sql.Connection,java.sql.DriverManager" %>
<%@ page import="java.net.URLDecoder" %>

<%
	//request.setCharacterEncoding("gb2312");
	//String id = request.getParameter("id");
	//int id = Integer.parseInt(id_str);
	//String trainNum = request.getParameter("trainNum");
	
	String cinema_name = request.getParameter("cinema_name");
	if (cinema_name != null && cinema_name.length() > 0)
		cinema_name = URLDecoder.decode(cinema_name, "UTF-8");
	if (cinema_name == null)
		cinema_name = "星空国际影城";
	String movie_Name = request.getParameter("movie_Name");
	if (movie_Name != null && movie_Name.length() > 0)
		movie_Name = URLDecoder.decode(movie_Name, "UTF-8");
	System.out.println(movie_Name);
	
	String date = request.getParameter("date");
	if (date != null && date.length() > 0)
		date = URLDecoder.decode(date, "UTF-8");
	
	
	
	//startStation = "北京";
	//cinema_name = "星空国际影城";
	//movie_Name = "疯狂原始人";
	//date = "12月10号";
	
	Connection con=null;
	Statement stmt=null;
	ResultSet rs=null;
	String driver="com.mysql.cj.jdbc.Driver";
	String url="jdbc:mysql://localhost:3306/android?serverTimezone=GMT&characterEncoding=utf-8";
	String user="root";
	String passwd="HandQuite229";
    try{
       Class.forName(driver);
       con=DriverManager.getConnection(url, user, passwd);
       if (con == null)
      		System.out.println("con is null");
       }catch(ClassNotFoundException e){
           out.println(e);
       }catch(SQLException e){
    	   out.println(e);
       }
	try{
		stmt=con.createStatement();
		String sql = "select * from tickets_info where cinema_name = '" + cinema_name + "' && movie_name = '" + movie_Name + "' && date = '" + date + "'";
		//String sql = "select * from cinema_item_info where movie_name = '" + movie_Name + "'";
		System.out.println(sql);
		rs=stmt.executeQuery(sql);
		
		out.println("[");
		
		while(rs.next()){
			out.println("{");
			out.println("\"cinema_name\":\"" + rs.getString(1) + "\"");
			out.println(",\"movie_name\":\"" + rs.getString(2) + "\"");
			out.println(",\"date\":\"" + rs.getString(3) + "\"");
			out.println(",\"start_time\":\"" + rs.getString(4) + "\"");
			out.println(",\"end_time\":\"" + rs.getString(5) + "\"");
			out.println(",\"language\":\"" + rs.getString(6) + "\"");
			out.println(",\"hall\":\"" + rs.getString(7) + "\"");
			out.println(",\"price\":\"" + rs.getDouble(8) + "\"");
			out.println("}");
			if (!rs.isLast()){
				out.println(",");
			}
        }
		
		out.println("]");
	}catch (SQLException ex) {
		out.println(ex);
	}
%>
